package com.networkviwer.listeners;

import com.networkviwer.networkviewer.NetworkViewer;

import javax.swing.*;
import javax.swing.table.JTableHeader;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.sql.SQLException;

/**
 * @version V1.0
 * @Title:
 * @Package
 * @Description:
 * @author: runoob
 * @date:
 */
public class TableHeaderListener implements MouseListener {
    JTable table;
    JTableHeader tableHeader;

    public TableHeaderListener(JTable table, JTableHeader tableHeader){
        this.table = table;
        this.tableHeader = tableHeader;
    }

    @Override
    public void mouseClicked(MouseEvent e) {

    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {
        int choose = tableHeader.columnAtPoint(e.getPoint());
        if (choose == 4){
            NetworkViewer.imageOder = 0;
            if (NetworkViewer.pidOrder == 0){
                NetworkViewer.pidOrder = 1;
            }else if(NetworkViewer.pidOrder == 1){
                NetworkViewer.pidOrder = -1;
            }else {
                NetworkViewer.pidOrder = 0;
            }
        }
        if (choose == 5){
            NetworkViewer.pidOrder = 0;
            if (NetworkViewer.imageOder == 0){
                NetworkViewer.imageOder = 1;
            }else if(NetworkViewer.imageOder == 1){
                NetworkViewer.imageOder = -1;
            }else {
                NetworkViewer.imageOder = 0;
            }
        }
        try {
            NetworkViewer.refreshData();
        } catch (SQLException | ClassNotFoundException ex) {
            ex.printStackTrace();
        }
    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}
